<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Axios GET 请求示例</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
  </head>
  <body>
    <div id="timeNow"></div>

    <script>
      // 使用 axios 发起 GET 请求
      (() => {
        axios({
          method: "get",
          url: "https://f.m.suning.com/api/ct.do",
          timeout: 20000, // 设置请求超时时间为 20 秒
        })
          .then((res) => {
            // 请求成功，处理响应数据
            console.log("响应数据：", res.data);
            // 提取 currentTime 并显示
            let currentTime = res.data.currentTime;
            let date = new Date(currentTime);
            document.getElementById("timeNow").innerText =
              "当前时间：" + date.toLocaleString();
          })
          .catch((err) => {
            // 请求失败，处理错误
            alert(err.code);
            if (err.code === "ECONNABORTED") {
              console.error("请求超时了");
            } else if (err.response) {
              console.error("响应有错误:", err.response.status);
            } else if (err.request) {
              console.error("发送了请求但没有收到响应:", err.request);
            } else {
              console.error("请求出错:", err.message);
            }
          });
      })();
      (() => {
        function Person(name, age, sex) {
          this.name = name;
          this.age = age;
          this.sex = sex;
          this.flag = 1;
        }
        Person.prototype = {
          func: () => {
            alert(123);
          },
          school: "TYUT",
          constructor: Person,
        };
        //Person.prototype.constructor = Person;
        let jie = new Person("接汉卿", "19", "男");
        //console.log(jie.name, jie.age, jie.sex);
        console.log(Person.prototype.constructor);
        //jie.func();
        console.log(jie.__proto__);
      })();
    </script>
  </body>
</html>
